<template>
  <view>
      <view class="homeSearch">
          <my-search @click=handlerSearch />
      </view>
     <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
       <swiper-item v-for="(item,i) in swiperList" :key="i">
         <view class="swiper-item" @click="handler(item.goods_id)"><image :src="item.image_src" mode=""></image></view>
       </swiper-item>
      
     </swiper>
      <view class="nav-item">
         <view v-for="(item,n) in navList" :key="n" class="nav-list" @click="navhandler(item.name)">
           <image :src="item.image_src" mode="" class="nav-image"></image>
         </view> 
      </view>
      <view class="fooler-item">
          <view class="fooler-list" v-for="(item,p) in floorList" :key="p" >
            <image :src="item.floor_title.image_src" mode="" class="fooler-title"></image>
            <view class="fooler-image">
            <view class="fooler-left"> 
              <view class="foolerList-item" @click="handlerFooler(item.product_list[0].url)">
                 <image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
              </view>     
            </view>
            <view class="fool-right">
              <view class="fooler-image" v-for="(i2,p2) in item.product_list" @click="handlerFoolerItem(item.product_list[p2].url)">
                <image :src="i2.image_src" v-if="p2!==0" :style="{width:i2.image_width+'rpx'}" mode="widthFix"></image>
              </view>
            </view>
                </view>
          </view>
      </view>
  </view>
</template>

<script>
  import badgeMix from "@/mixins/tabbar-badge.js"
  export default {
      mixins:[badgeMix],
    data() {
      return {
        swiperList:[],
        navList:[],
        floorList:[],
      };
    },
    onLoad(){
      // 调用方法
      this.getSwiperList()
      this.getNavList()
      this.getFloorList()
    },
    methods:{
      handlerSearch(){
       uni.navigateTo({
         url:"/subpkg/search/search"
       })
      },
handlerFoolerItem(url){
        uni.navigateTo({
          url:url
        })
     },
     navhandler(name){
       if(name==="分类"){
         uni.switchTab({
           url:"/pages/cate/cate"
         })
       }
     },
     handlerFooler(url){
       uni.navigateTo({
         url:url
       })
     },
      handler(id){
       uni.navigateTo({
         url:`/subpkg/goods_detail/goods_detail?goods_id=${id}`
       })
      },  
      
     async getFloorList(){
         const {data:res}=await uni.$http.get("/api/public/v1/home/floordata")
          console.log(res)
          if(res.meta.status!==200){
            return uni.$showmag("数据请求失败",1000,"none")
          }
          res.message.forEach(floor=>{
            floor.product_list.forEach(prod=>{
              prod.url="/subpkg/goods_list/goods_list?"+prod.navigator_url.split("?")[1]
            })
          })
          this.floorList=res.message
          uni.$showmag('数据请求成功',2000,"none")
      },
     async getNavList(){
        const {data:res}=await uni.$http.get("/api/public/v1/home/catitems")
         
          if(res.meta.status!==200){
            return uni.$showmag("数据请求失败",1000,"none")
          }
          this.navList=res.message
          uni.$showmag('数据请求成功',2000,"none")
      },
      
      async getSwiperList(){
       const {data:res}= await uni.$http.get("/api/public/v1/home/swiperdata")
      // 请求失败
      if(res.meta.status!==200){
        return uni.$showmag("数据请求失败",1000,"none")
      }
      this.swiperList=res.message
      uni.$showmag('数据请求成功',2000,"none")
      }
    }
    
  }
</script>

<style lang="scss">
swiper{
  height: 330rpx;
  .swiper-item,image{
    width: 100%;
    height: 100%;
  }}
  .nav-item{
    display: flex;
    justify-content: space-around;
    margin:15px 0;
     .nav-image{
    width:128rpx;
    height:140rpx;
  }
  }
 .fooler-title{
   width: 100%;
   height: 60rpx;
 }
.fool-right{
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}
.fooler-image{
  display: flex;
}
.fooler-left{
  padding-left: 10px;
}
.homeSearch{
  position: sticky;
  top: 0;
  z-index: 999;
}
</style>



